package org.aliwo.runnable;

/**
 * @author xuyayuan
 * @data 2021年06月12日
 */
public class Thead02 {
    public static void main(String[] args) {
        person1 person1 = new person1();
        person2 person2 = new person2();

        Thread thread1 = new Thread(person1);
        Thread thread2 = new Thread(person2);
        thread1.start();
        thread2.start();
    }
}

class person1 implements Runnable {

    int num = 0;

    @Override
    public void run() {

        while (true) {
            System.out.println("多线程交替执行 Thread1 :" + " 线程名 : " + Thread.currentThread().getName() + " " +(++num));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (10 == num) {
                break;
            }
        }
    }
}


class person2 implements Runnable {
    int num = 0;

    @Override
    public void run() {
        while (true) {
            System.out.println("多线程交替执行 Thread2 :" + " 线程名 : " + Thread.currentThread().getName() + " " +(++num));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (5 == num) {
                break;
            }
        }
    }
}